#!/usr/bin/env python

# To run the tests
#     TestPrimes.py

# To document the tests
#     pydoc -w TestPrimes

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    """
    TestReader is a class that was implemented to test the
    reading of main
    """
    def __init__ (self, s) :
        """
        the TestReader class initializes with parameterized s,
        expected type of parameterized s is a Reader from main
        """
        self.s = s

    def read (self) :
        """
        read method returns the object that was passed
        through the initialization of TestReader
        """
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    """
    TestWriter is a class that was implemented to test the
    writing part of main
    """
    def str (self) :
        """
        str method of TestWriter will return the string stored
        as a temporary value as s
        """
        return self.s

    def write (self, *a) :
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestCollatz
# -----------

class TestPrimes (unittest.TestCase) :
    """
    TestCollatz has been created to test various functions
    implemented in main, extending a unittest.TestCase class.
    """
    # ----
    # read
    # ----

    def test_read (self) :
        """
        test_read tests reading method of main by using TestReader
        """
        reader = TestReader('10\n')
        main.my_read(reader)
        self.assert_(main.i ==  10)

    # -----
    # eval1
    # -----

    def test_eval1 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  1
        main.my_eval()
        self.assert_(main.out == 'Impossible.')

    # -----
    # eval2
    # -----
    
    def test_eval2 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  10000001
        main.my_eval()
        self.assert_(main.out == 'Impossible.')

    # -----
    # eval3
    # -----
    
    def test_eval3 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  8
        main.my_eval()
        self.assert_(main.out == '2 2 2 2')

    # -----
    # eval4
    # -----
    
    def test_eval4 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  1000009
        main.my_eval()
        self.assert_(main.out == '2 3 43 999961')

    # -----
    # eval5
    # -----
    
    def test_eval5 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  1000000
        main.my_eval()
        self.assert_(main.out == '2 2 13 999983')

    # -----
    # eval6
    # -----
    
    def test_eval6 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  7
        main.my_eval()
        self.assert_(main.out == 'Impossible.')

    # -----
    # eval7
    # -----
    
    def test_eval6 (self) :
        """
        test_eval1 is one of 7 different methods of TestPrimes that
        tests the evaluation part of main
        """
        main.i =  -100
        main.my_eval()
        self.assert_(main.out == 'Impossible.')

    # -----
    # print
    # -----

    def test_print (self) :
        """
        test_print tests printig/writing method of main by using
        TestWriter
        """
        main.out = '3 11 3 7'
        writer = TestWriter()
        main.my_print(writer)
        self.assert_(writer.str() == '3 11 3 7\n')

if __name__ == "__main__" :
    unittest.main()
